﻿using deviceManage.Models;
using deviceManage.VO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace deviceManage.Service
{
    /// <summary>
    /// 设备管理
    /// </summary>
    public class DeviceService
    {
        private readonly DeviceCtx _context;
        public DeviceService(DeviceCtx _context)
        {
            this._context = _context;
        }

        
        


        public Device GetById(string id)
        {
            return _context.Device.Single(p => p.Id == id);
        }

        public void updateDevice(Device device)
        {
            _context.Device.Update(device);
            _context.SaveChanges();
        }

        public void Delete(string id)
        {
            var d = this.GetById(id);
            d.Deleted = 1;
            d.Status = DeviceState.STATE_DELETED;
            _context.Device.Update(d);
            _context.SaveChanges();
        }

        /// <summary>
        /// 恢复被删除的设备
        /// </summary>
        /// <param name="id"></param>
        public void Revert(string id)
        {
            var d = this.GetById(id);
            d.Deleted = 0;
            d.Status = DeviceState.STATE_NORMAL ;
            _context.Device.Update(d);
            _context.SaveChanges();
        }

        
    }
}
